<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>天津市西青医院满意度调查问卷</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<%=basePath%>dist/css/AdminLTE.min.css">
    <!-- Validator style -->
    <link href="<%=basePath %>bootstrap/bootstrapvalidator/dist/css/bootstrapValidator.min.css" rel="stylesheet"/>

</head>
<body class="hold-transition login-page">
<div class="login-box">
    <div class="login-logo">
        <a href="<%=basePath%>"><b>满意度调查系统</b></a>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg"></p>

        <form  method="post" id="defaultForm">
            <div class="form-group has-feedback ">
                <input type="text" name="username" id="username" class="form-control" placeholder="用户名">
                <span class="help-block"></span>
            </div>
            <div class="form-group has-feedback ">
                <input type="password" name="pword" id="pword" class="form-control" placeholder="密码">
                <span class="help-block"></span>
            </div>
            <div class="row">
                <div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label class="">
                            <div class="icheckbox_square-blue" aria-checked="false" aria-disabled="false"
                                 style="position: relative;"><input type="checkbox"
                                                                    style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;">
                                <ins class="iCheck-helper"
                                     style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>
                            </div>
                        </label>
                    </div>
                </div>
                <!-- /.col -->
                <div class="col-xs-4">
                    <button type="button" class="btn btn-primary btn-block btn-flat" id="loginbtn">登录</button>
                </div>
                <!-- /.col -->
            </div>
        </form>


    </div>
    <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 3 -->
<script src="<%=basePath%>bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="<%=basePath%>bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Validator 3.3.7 -->
<script src="<%=basePath %>bootstrap/bootstrapvalidator/dist/js/bootstrapValidator.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrapvalidator/dist/js/language/zh_CN.js"></script>
<!-- bootbox -->
<script src="<%=basePath %>bootstrap/bootbox/bootbox.min.js"></script>
<script src="<%=basePath %>bootstrap/commend/initcommend.js"></script>
<script>
    $(function () {
        $("#username").focus();
        $('#pword').bind('keypress',function(event){
            if(event.keyCode == "13")
            {
                $("#defaultForm").bootstrapValidator('validate');//提交验证
                if ($("#defaultForm").data('bootstrapValidator').isValid()) {
                    var dialog = bootbox.dialog({
                        title: '满意度调查系统',
                        message: '<p><i class="fa fa-spin fa-spinner"></i> 请稍等...</p>'
                    });
                    $.post(getRootPath_web()+"/user/userLogin",{
                        username:$("#username").val(),
                        password:$("#pword").val()
                    },function (data) {
                        if (data){
                            dialog.modal('hide');
                            window.location.href=getRootPath_web()+"/jsp/index.jsp";
                        } else{
                            dialog.modal('hide');
                            bootbox.alert("用户名密码错误");
                            return
                        }
                    },'json').fail(function (jqXHR, textStatus, errorThrown) {
                        bootbox.alert(jqXHR.responseJSON.message);
                    })
                }

                return false;
            }
        });
        $("#defaultForm").bootstrapValidator({
            excluded: [":hidden"],
            live: 'disabled',//验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
            feedbackIcons: {//根据验证结果显示的各种图标
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                username: {
                    //trigger: "change",
                    validators: {
                        notEmpty: {
                            message: '用户名不能为空'
                        }
                    }
                },
                pword: {
                    //trigger: "change",
                    validators: {
                        notEmpty: {
                            message: '密码不能为空'
                        }
                    }
                }
            }
        });

        $("#loginbtn").click(function () {
            $("#defaultForm").bootstrapValidator('validate');//提交验证
            if ($("#defaultForm").data('bootstrapValidator').isValid()) {
                var dialog = bootbox.dialog({
                    title: '满意度调查系统',
                    message: '<p><i class="fa fa-spin fa-spinner"></i> 请稍等...</p>'
                });
                $.post(getRootPath_web()+"/user/userLogin",{
                    username:$("#username").val(),
                    password:$("#pword").val()
                },function (data) {
                    if (data){
                        window.location.href=getRootPath_web()+"/jsp/index.jsp";
                    } else{
                        dialog.modal('hide');
                        bootbox.alert("用户名密码错误");
                    }
                },'json').fail(function (jqXHR, textStatus, errorThrown) {
                    bootbox.alert(jqXHR.responseJSON.message);
                })
            }
        })
    })
</script>


</body>
</html>